package GUI;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.*;

import Joc.Joc;
import Joc.JocStates;
import Model.EroareLCVMessagesThreeAnimals;
import Model.HandlerMessagesLCV;

public class IntroducereDateLupCapraVarza  {
	JFrame frame;
	JPanel panelIntroducereDateLCV;
	public JCheckBox varza_mal_stang, varza_mal_drept, lup_mal_stang, lup_mal_drept, oaie_mal_stang, oaie_mal_drept;
	JButton buttonSave;
	JButton buttonCancel;
	JLabel label;
	public static ArrayList<String> date;

	public IntroducereDateLupCapraVarza() {
		frame=new JFrame("Introducere Date Puzzle");
		panelIntroducereDateLCV = new JPanel();
		panelIntroducereDateLCV.setLayout(null);

		ImageIcon newIcon = new ImageIcon("Lup_Capra_Varza.png");
		label = new JLabel();
		label.setIcon(newIcon);
		label.setBounds(5, 20, 410, 100);
		panelIntroducereDateLCV.add(label);

		varza_mal_stang = new JCheckBox();
		varza_mal_stang.setBounds(10, 110, 40, 25);
		varza_mal_stang.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent event) {
				JCheckBox cb = (JCheckBox) event.getSource();
				if (cb.isSelected()) {
					varza_mal_drept.setSelected(false);
				}
			}
		});
		panelIntroducereDateLCV.add(varza_mal_stang);

		oaie_mal_stang = new JCheckBox();
		oaie_mal_stang.setBounds(60, 110, 40, 25);
		oaie_mal_stang.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent event) {
				JCheckBox cb = (JCheckBox) event.getSource();
				if (cb.isSelected())
					oaie_mal_drept.setSelected(false);
			}
		});
		panelIntroducereDateLCV.add(oaie_mal_stang);

		lup_mal_stang = new JCheckBox();
		lup_mal_stang.setBounds(110, 110, 40, 25);
		lup_mal_stang.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent event) {
				JCheckBox cb = (JCheckBox) event.getSource();
				if (cb.isSelected())
					lup_mal_drept.setSelected(false);
			}
		});
		panelIntroducereDateLCV.add(oaie_mal_stang);
		panelIntroducereDateLCV.add(lup_mal_stang);

		varza_mal_drept = new JCheckBox();
		varza_mal_drept.setBounds(280, 110, 40, 25);
		varza_mal_drept.setSelected(true);
		varza_mal_drept.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent event) {
				JCheckBox cb = (JCheckBox) event.getSource();
				if (cb.isSelected())
					varza_mal_stang.setSelected(false);
			}
		});
		panelIntroducereDateLCV.add(varza_mal_drept);

		oaie_mal_drept = new JCheckBox();
		oaie_mal_drept.setBounds(330, 110, 40, 25);
		oaie_mal_drept.setSelected(true);
		oaie_mal_drept.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent event) {
				JCheckBox cb = (JCheckBox) event.getSource();
				if (cb.isSelected())
					oaie_mal_stang.setSelected(false);
			}
		});
		panelIntroducereDateLCV.add(oaie_mal_drept);

		lup_mal_drept = new JCheckBox();
		lup_mal_drept.setBounds(380, 110, 40, 25);
		lup_mal_drept.setSelected(true);
		lup_mal_drept.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent event) {
				JCheckBox cb = (JCheckBox) event.getSource();
				if (cb.isSelected())
					lup_mal_stang.setSelected(false);
			}
		});
		panelIntroducereDateLCV.add(lup_mal_drept);

		buttonSave = new JButton("Save");
		buttonSave.setBounds(110, 200, 70, 25);
		buttonSave.addActionListener(new Action());
		panelIntroducereDateLCV.add(buttonSave);

		buttonCancel = new JButton("Cancel");
		buttonCancel.setBounds(200, 200, 80, 25);
		buttonCancel.addActionListener(new Action());
		panelIntroducereDateLCV.add(buttonCancel);

		frame.add(panelIntroducereDateLCV);
		frame.setSize(440, 300);
		frame.setVisible(true);
		frame.setResizable(false);
	}

	class Action implements ActionListener {
		@Override
		public void actionPerformed(ActionEvent e) {
			if (e.getSource() == buttonCancel){
				frame.dispose();
				MassagePanel.clearMessagesPanel();
				MassagePanel.writeMessagePanel("Start the Game!");
			}
			else if (e.getSource() == buttonSave) {
				HandlerMessagesLCV handMessalcv = new EroareLCVMessagesThreeAnimals();
				if (handMessalcv.HandleRequest(getDataFromComboBox())==false){
					MassagePanel.writeMessagePanel("[INFO] Datele pentru lup-oaie-varza s-au introdus corect");
					date = getDataFromComboBox();
					Joc j=Joc.getJocinstance();
					j.setState(JocStates.LCV);
					j.setInitialvalue(getDataFromComboBox());
					SimulareDesenPanel.textdesen.setText("");
				}
				//System.out.println();
			}
		}

		
	}
	public ArrayList<String> getDataFromComboBox() {
		// TODO Auto-generated method stub
		ArrayList<String> list=new ArrayList<String>();
		if(varza_mal_stang.isSelected())
			list.add("true");
		else list.add("false");
		
		if(oaie_mal_stang.isSelected())
			list.add("true");
		else list.add("false");
		
		if(lup_mal_stang.isSelected())
			list.add("true");
		else list.add("false");
		
		if(varza_mal_drept.isSelected())
			list.add("true");
		else list.add("false");
		
		if(oaie_mal_drept.isSelected())
			list.add("true");
		else list.add("false");
		
		if(lup_mal_drept.isSelected())
			list.add("true");
		else list.add("false");
		
		return list;
	}

}
